# uncompyle6 version 3.2.3
# Python bytecode 3.6 (3379)
# Decompiled from: Python 3.6.8 |Anaconda custom (64-bit)| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
# Embedded file name: server\http_responses\http_status_codes.py
__author__ = "sanyi"
from server.http_responses.json_serializable import JsonSerializableResponse
from server.http_responses.base import BaseResponse


class Http302(BaseResponse):
    def __init__(self, location, headers=None, cookie=None):
        if headers is None:
            headers = dict(Location=location)
        else:
            headers["Location"] = location
        super().__init__(b"", headers, response_status="302 Found", cookie=cookie)


class Http204(BaseResponse):
    def __init__(self, headers=None, cookie=None):
        super().__init__(b"", headers, response_status="204 No Content", cookie=cookie)


class Http201(JsonSerializableResponse):
    def __init__(self, location, body=None, headers=None, cookie=None):
        if headers is None:
            headers = dict(Location=location)
        else:
            headers["Location"] = location
        super().__init__(body, headers, response_status="201 Created", cookie=cookie)


class Http200(JsonSerializableResponse):
    def __init__(self, body=None, headers=None, cookie=None):
        super().__init__(body, headers, response_status="200 OK", cookie=cookie)


class Http200File(BaseResponse):
    def __init__(
        self,
        file_name,
        body=None,
        content_type="application/octet-stream",
        headers=None,
        cookie=None,
    ):
        if headers is None:
            headers = dict()
        headers["Content-Disposition"] = "attachment; filename=%s" % file_name
        headers["Content-type"] = content_type
        super().__init__(body, headers, response_status="200 OK", cookie=cookie)


class HTTPFileChunkReceived(BaseResponse):
    def __init__(self, chunk_start, chunk_end, file_size, headers=None, cookie=None):
        if chunk_end + 1 == file_size:
            super().__init__(b"", headers, response_status="204 OK", cookie=cookie)
            return
        size_info = "%s-%s/%s" % (chunk_start, chunk_end, file_size)
        if headers is None:
            headers = dict(Range=size_info)
        else:
            headers["Range"] = size_info
        if chunk_start == 0:
            super().__init__(
                size_info.encode(),
                headers,
                response_status="201 Created",
                cookie=cookie,
            )
        else:
            super().__init__(
                size_info.encode(),
                headers,
                response_status="202 Accepted",
                cookie=cookie,
            )
